package com.banciyuan.bcywebview.base.view.other;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.util.AttributeSet;
import android.view.View;

import com.banciyuan.bcywebview.R;

/**
 * Created by squall on 2016/9/9.
 */
public class RightBubleShape extends View {

    private int color;

    public RightBubleShape(Context context) {
        super(context);
    }

    public RightBubleShape(Context context, AttributeSet attrs) {
        super(context, attrs);
        getAttr(context,attrs);
    }

    public RightBubleShape(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        getAttr(context,attrs);
    }

    public RightBubleShape(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        getAttr(context,attrs);
    }

    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        int w = getWidth();
        Path path = new Path();
        path.moveTo(0, 0);
        path.lineTo(w - w / 2, w / 2);
        path.lineTo(0, w);
        path.lineTo(0, 0);
        path.close();

        Paint p = new Paint();
        p.setAntiAlias(true);
        p.setColor(color);

        canvas.drawPath(path, p);
    }

    private void getAttr(Context context, AttributeSet attrs) {
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BubleShape);
        color = a.getColor(R.styleable.BubleShape_bubleColor, getResources().getColor(R.color.blue));
    }
}
